﻿using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace G2Tech.Gadgeteer.MountaineerLed
{
    /// <summary>
    /// pins used on the mainboard, not on a Gadgeteer socket
    /// </summary>
    public class MountaineerHardware
    {
        /// <summary>
        /// on-board switch, PE10
        /// </summary>
        public const Cpu.Pin Button = (Cpu.Pin)74;

        /// <summary>
        /// on-board LED Green, PE11/PWM_CH5
        /// </summary>
        public const Cpu.Pin LedGreen = (Cpu.Pin)75;

        /// <summary>
        /// on-board LED Green, PE11/PWM_CH5
        /// </summary>
        public const Cpu.PWMChannel PwmGreen = Cpu.PWMChannel.PWM_5;

        /// <summary>
        /// on-board LED Red, PE13/PWM_CH6
        /// </summary>
        public const Cpu.Pin LedRed = (Cpu.Pin)77;

        /// <summary>
        /// on-board LED Red, PE13/PWM_CH6
        /// </summary>
        public const Cpu.PWMChannel PwmRed = Cpu.PWMChannel.PWM_6;

        /// <summary>
        /// on-board LED Blue, PE14/PWM_CH7
        /// </summary>
        public const Cpu.Pin LedBlue = (Cpu.Pin)78;

        /// <summary>
        /// on-board LED Blue, PE14/PWM_CH7
        /// </summary>
        public const Cpu.PWMChannel PwmBlue = Cpu.PWMChannel.PWM_7;

        /// <summary>
        /// Determine whether this is a USB mainboard or an Ethernet mainboard.
        /// </summary>
        /// <returns>True if the mainboard is USB mainboard</returns>
        public static bool IsUsbMainboard()
        {
            using (InputPort boardId = new InputPort((Cpu.Pin)55, false, Port.ResistorMode.Disabled))
            {
                return boardId.Read();
            }
        }
    }
}
